package com.wc.alorithm_blue_bridge._枚举.九宫幻方;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/10 11:01
 * @description https://www.lanqiao.cn/problems/100/learning/?page=1&first_category_id=1&second_category_id=3
 */
public class Main {
    /**
     * 思路：暴力枚举, vis[i] = -1 表示 i 这个数字不可用
     * vis[i] = 0 表示 i 这个数字没用过
     * vis[i] = 1 表示 i 这个数字用过了
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 3, M = 20;
    static int[] res = new int[M];
    static int idx = 0;
    static int[][] a;
    static int[][] g = new int[N][N];

    public static void main(String[] args) {
        init();
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                g[i][j] = sc.nextInt();
            }
        }
        Arrays.sort(res, 1, idx + 1);
        int j = 1;
        // 去重
        for (int i = 1; i <= idx; i++) {
            if (res[i] != res[j]) res[++j] = res[i];
        }
        int x = cal(g), ans = 0;
        idx = j;
        for (int i = 1; i <= idx; i++) {
            if (compare(x, res[i])) {
                if (ans == 0) ans = i;
                else {
                    ans = -1;
                    break;
                }
            }
        }
        if (ans == -1) out.println("Too Many");
        else {
            ans = res[ans];
            String s = String.valueOf(ans);
            for(int i = 1; i <= 9; i++){
                out.print(s.charAt(i - 1) + " ");
                if (i % 3 == 0) out.println();
            }
        }
        out.flush();
    }

    static boolean compare(int a, int b) {
        for (int i = 1; i <= 9; i++) {
            if (a % 10 != 0 && a % 10 != b % 10) return false;
            a /= 10;
            b /= 10;
        }
        return true;
    }

    static int cal(int[][] a) {
        int res = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                res = res * 10 + a[i][j];
            }
        }
        return res;
    }

    static void init() {
        a = new int[][]{
                {6, 7, 2},
                {1, 5, 9},
                {8, 3, 4}
        };

        for (int i = 0; i < 4; i++) {
            a = roll(a);
            res[++idx] = cal(a);
        }
        a = mirror1(a);
        for (int i = 0; i < 4; i++) {
            a = roll(a);
            res[++idx] = cal(a);
        }
        a = mirror1(a);
        a = mirror2(a);
        for (int i = 0; i < 4; i++) {
            a = roll(a);
            res[++idx] = cal(a);
        }
        a = mirror2(a);
    }

    // 顺时针旋转90度
    static int[][] roll(int[][] a) {
        int[][] b = new int[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                b[j][N - i - 1] = a[i][j];
            }
        }
        return b;
    }

    // 左右对称镜像
    static int[][] mirror1(int[][] a) {
        int[][] b = new int[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                b[i][N - j - 1] = a[i][j];
            }
        }
        return b;
    }

    // 上下对称
    static int[][] mirror2(int[][] a) {
        int[][] b = new int[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                b[N - i - 1][j] = a[i][j];
            }
        }
        return b;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
